package data;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;

/**
 * @author 	luhongzhe
 * @email  	azhe0660@gmail.com
 * @date   	2011-10-13
 */

public class ObjectDrawable extends Drawable
{
	private ObjectPath path;
	private ObjectPath scalePath;
	
	private int width;
	private int height;
	
	public void setPath(ObjectPath path, int width, int height)
	{
		this.path = path;
		this.width = width;
		this.height = height;
		
		Matrix matrix = new Matrix();
		matrix.preScale(width / 100, height / 100);
		scalePath = path.transform(matrix);
	}
	
	public void moveTo(int x, int y)
	{
		this.setBounds(x, y, x + width, y + height);
	}
	
	@Override
	public void draw(Canvas canvas)
	{
		if (path == null)
			return;
		
		Rect bounds = getBounds();
		
		Paint paint = new Paint();
		paint.setColor(Color.RED);
		canvas.drawRect(bounds, paint);
		
		canvas.save();
		canvas.translate(bounds.left, bounds.top);
		int size = scalePath.size;
		for (int i = 0; i < size; i++)
		{
			paint.setColor(scalePath.fillColors[i]);
			canvas.drawPath(scalePath.paths[i], paint);
		}
		canvas.restore();
	}

	@Override
	public void setAlpha(int alpha) {
		// TODO Auto-generated method stub

	}

	@Override
	public void setColorFilter(ColorFilter cf) {
		// TODO Auto-generated method stub

	}

	@Override
	public int getOpacity() {
		// TODO Auto-generated method stub
		return 0;
	}

}
